﻿package com.shuqi.sdk.ad;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.apache.http.message.BasicNameValuePair;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.pubukeji.diandeows.adviews.DiandeBanner;
import com.pubukeji.diandeows.adviews.DiandeResultCallback;
import com.shuqi.common.Config;
import com.shuqi.common.MyTask;
import com.shuqi.common.utils.Log4an;
import com.shuqi.common.utils.Util;
import com.shuqi.interfaces.EventTypeConstants;
import com.shuqi.interfaces.IEventListener;
import com.shuqi.model.ModelBase;
import com.shuqi.model.net.HttpRequest;
import com.shuqi.model.net.UrlManager;
import com.shuqi.model.net.listener.HttpRequestListener;
import com.shuqi.model.parse.HandlerBase;
import com.shuqi.model.sharedprefs.WebDomains;
import com.shuqi.statistics.StatisticsEventID;
import com.shuqi.statistics.StatisticsUtils;

/**
 * 广告主类
 * 
 * @author Arthur Jin
 * @version 3.3
 */
public class ADView implements IEventListener {
    private final String Tag = "ADView";

    /** 自主广告显示图片的对象 */
    private Bitmap adBackground = null;// 最老的广告背景 110422

    /** 艾德思奇广告 **/
    // private com.mobisage.android.MobiSageAdBanner mobisageBanner;

    /** 谷歌的广告对象 */
    // private IMBanner imBannerAdView;

    // /** 宜搜的广告对象*/
    // private AdSwitchLayout adSwitchLayout;

    /** 自主广告显示时的内容 */
    private String content = null;// 老广告的content 110816
    /** 自主广告显示时的链接 */
    private String link = null;
    /** 自主广告显示时的类型 */
    private String show_type = null;
    /** 当前显示广告的序号 */
    private int whichAd;
    /** 显示广告的Activity */
    private Activity context;
    /** 要隐藏的View的id */
    private int hideID;
    /** 要显示广告的layout的id */
    private int layoutID;
    /** 广告显示位置的序号 */
    private int adPos;
    /** 管理广告显示的网址 */
    private String url;
    /** ConfigVersion */
    private String config_version;
    /** 每个广告所需的广告id */
    private Object[][] adID;
    /** 广告事件回调监听 */
    private Listener listener;
    /** 要测试的广告序号 */
    private int testADID;

    /* 显示下一个广告用 */
    float maxRate = Float.MAX_VALUE;
    int maxIndex = -1;
    /** 已经显示过哪些广告 */
    private List<Integer> showedAd;
    /** 广告包名关键字 */
    private static String[] adKeyWord = new String[] {null,// 0：自主广告
            null,// 1：madhouse 已下架
            null,// 2：adchina(old)已下架
            null,// 3：iMocha 已下架
            "adwo",// 4：adwo
            null,// 5：vpon 已下架
            null,// 6：umeng友盟 已下架
            null,// 7：baidu百度 已下架
            null,// 8：帷千广告 已下架
            null,// 9：LSense(已下架)
            null,// 10：youmi
            "domob",// 11：domob多盟
            null,// 12：adchina(new) 已下架
            "mobwin",// 13：mobwin聚赢
            null,// 14：suizong 下架
            "mobisage",// 15：mobisage
            null,// 16：dianru
            null,// 17://moku下架
            null,// 18://qumi下架
            // 19到26 是自主广告 仇伟序号
            null,// 27:PunchBox 下架 -->29
            null,// 28:PunchBox 下架 -->30
            "",// 29：PingCoo -->31
            null,// 30: mobwin聚赢 下架-->32
            null,// 31:punchbox -->33下架
            "qq",// 32:gdt ad -->34
            null,// 33:yunyun ad 下架 -->35

            null,// adsmogo 34 7.3.3 芒果 下架 -->36
            "InMobi",// 35 测试 谷歌 -->37
            "easou",// 36 测试 宜搜 --> 38 easou
            "360dianjing" // 37 39 360点睛
    };

    /**
     * @param context Activity对象
     * @param hideID 要隐藏的View的id
     * @param layoutID 要添加广告的layout
     * @param adPos 广告位置
     * @param url 广告连网地址
     * @param config_version config中的version
     * @param adID 每个广告所需的广告id
     * @param testADID 要测试的广告id
     */
    public ADView(Activity context, int hideID, int layoutID, int adPos, String url,
            String config_version, int testADID) {
        this.context = context;
        this.hideID = hideID;
        this.layoutID = layoutID;
        this.adPos = adPos;
        this.url = url;
        this.config_version = config_version;
        this.testADID = testADID;
        showedAd = new ArrayList<Integer>();
    }

    public ADView(Activity context, int adPos, String url, String config_version, int testADID) {
        this.context = context;
        this.adPos = adPos;
        this.url = url;
        this.config_version = config_version;
        this.testADID = testADID;
        showedAd = new ArrayList<Integer>();
    }

    /**
     * 初始化广告id By Tim
     */
    public void initADIDAdapter() {
        this.adID = new Object[][] { {0},// 0
                {"90001787"}, // 1
                {}, // 2
                {"3901"},// 3
                {"dcdb2d33ab694e02a0c1c77bf9ccf83f"},// 4
                {"f2d0d34b3189905201318e87551a0055"},// 5
                {"10020", "10076"},// 6
                {0},// 7
                {}, // 8
                {}, // 9
                {"a267b91f05acd349", "679b323e3bb6bbf9"},// 10
                {"56OJyMmIuMG49V/uFo", "16TLweKoAchs2Y6RCbUjjuUi"},// 11 domob
                {"74644"},// 12
                {0},// 13
                {""},// 14 suizong 下架
                {"524ee81032f7487d9072f2d0785c581a"},// 15
                {0},// 16
                {},// 17
                {"14d785577c1beb78", "4e3208ee45d1dc08"},// 18
                // 接下来是9个自主广告
                {0}, // 19
                {0}, // 20
                {0}, // 21
                {0},// 22
                {0}, // 23
                {0}, // 24
                {0}, // 25
                {0},// 26
                {0},// 27PunchBox
                {0},// 28PunchBox新增一个广告id
                {""},// 29PingCoo 1369021242404
                {},// 30 聚赢
                {"16252171-7DE8-159E-F72B-9A58CFD2D08D"},// 31PunchBox
                {"72058698764967056"},// 32 gdt ad 288231536615871695|72058698764967056
                {0},// 33 yunyun ad 下架

                {},// 34 // adsmogo芒果 b6ebca89a6e249e3acc1b4c6ef47b477
                {"cc09923079c8402bb28797fe65580e14"},// 35 // InMobi 谷歌
                {"4302_94"},// 36 // easou 宜搜联盟 4302_94
                {"168e3e01b722ad044ce9ddd1266220d5"}// 37 // 360点睛广告
                };
    }

    /**
     * 记录广告崩溃
     */
    public static void recordAdCrashLog(Context context, String crashlog) {
        try {
            if (!TextUtils.isEmpty(crashlog)) {
                crashlog = crashlog.toLowerCase();
                for (int i = 0; i < adKeyWord.length; i++) {
                    if (adKeyWord[i] != null && crashlog.contains(adKeyWord[i])) {
                        SharedPreferences sp =
                                context.getSharedPreferences("sdk", Context.MODE_PRIVATE);
                        Editor ed = sp.edit();
                        // 记录崩溃的是哪个广告，还要区分版本
                        ed.putString(Config.VERSION_INFO + "_" + i, null);
                        ed.commit();
                        Log4an.e("=============", Config.VERSION_INFO + "_" + i);
                        break;
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    List<AdvertisingInfo> list = new ArrayList<ADView.AdvertisingInfo>();
    SharedPreferences sp;
    Editor ed;
    boolean isShowAd;
    long lastTime;
    long currentTime;

    private static final String SHAREDPREFERENCE_FIRST_NAME = "checkad";

    /**
     * 连网检查是否显示广告等
     * 
     * @param isADViewLoading 是否是开屏广告
     */
    public void checkIsAdShown(boolean isADViewLoading) {
        if (Util.isNetworkConnected(context)) {
            final AdvertisingApp adModel = new AdvertisingApp(context);
            adModel.addEventListener(this);

            // 1.6以下不显示广告
            if (android.os.Build.VERSION.SDK_INT <= 4)
                return;
            sp =
                    context.getSharedPreferences(SHAREDPREFERENCE_FIRST_NAME + adPos,
                            Context.MODE_PRIVATE);
            ed = sp.edit();
            isShowAd = sp.getBoolean("isshowad", true);
            lastTime = sp.getLong("time", 0);
            currentTime = System.currentTimeMillis();
            if (currentTime - lastTime >= 1000*60*30) {
                adModel.loadData();
            } else {
                Log4an.d("yjd", "isADViewLoading="+isADViewLoading);
                if (!isADViewLoading) {
                    if (isShowAd) {
                        initAd();
                    } else {
                        if (listener != null) {
                            listener.onIsShowAd(false);
                        }
                    }
                }
            }
        }
    }

    private void addData() {
        ed.putLong("time", currentTime);
        ed.commit();
        Log.e(Tag, "checkIsShowAd");
        if (list == null || list.size() == 0) {

            // Log4an.d("----->", list == null ? null :
            // list.get(0).getRatio());

            if (isShowAd) {
                initAd();
            } else {
                if (listener != null) {
                    listener.onIsShowAd(false);
                }
            }
        } else if ("1".equals(list.get(0).getStatus())) {

            // Log4an.d("----->", list.get(0).getRatio());

            ed.putBoolean("isshowad", true);
            ed.putString("which", list.get(0).getRatio());
            ed.putString("content", list.get(0).getContent());
            ed.putString("link", list.get(0).getLink());
            ed.putString("show_type", list.get(0).getShow_type());
            ed.putString("selfadids", list.get(0).getSelfadids());
            String[] selfadids = list.get(0).getSelfadids().split(":");

            Log.d(Tag, "----->" + selfadids[0]);

            if (selfadids != null && selfadids.length > 0) {
                Log.d(Tag, "selfadids.length=" + selfadids.length);
                for (int i = 0; i < selfadids.length; i++) {
                    try {
                        ed.putString("selfadid" + selfadids[i] + "content", list.get(i + 1)
                                .getContent());
                        ed.putString("selfadid" + selfadids[i] + "link", list.get(i + 1).getLink());
                        ed.putString("selfadid" + selfadids[i] + "show_type", list.get(i + 1)
                                .getShow_type());

                        Log.d(Tag,
                                "selfadids content="
                                        + sp.getString("selfadid" + selfadids[i] + "content", null)
                                        + ",link="
                                        + sp.getString("selfadid" + selfadids[i] + "link", null));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            ed.commit();
            initAd();
        } else {
            if (listener != null) {
                listener.onIsShowAd(false);
            }
            ed.putBoolean("isshowad", false);
            ed.commit();
        }
    }

    /** 初始化广告参数 */
    private void initAd() {
        try {
            whichAd = -1;
            float rate[] = null;
            SharedPreferences sp =
                    context.getSharedPreferences(SHAREDPREFERENCE_FIRST_NAME + adPos,
                            Context.MODE_PRIVATE);
            String bz = sp.getString("which", "");
            if ("".equals(bz)) {
                whichAd = -1;
            } else {
                if (bz.endsWith(":")) {
                    bz = bz.substring(0, bz.length() - 1);
                }
                List<Float> bzList = new ArrayList<Float>();
                int index = 0;
                int index2 = 0;
                while (true) {
                    index = bz.indexOf(":", index2);
                    if (index == -1) {
                        try {
                            bzList.add(Float.valueOf(bz.substring(index2)));
                        } catch (NumberFormatException e) {
                            bzList.add(1f);
                            e.printStackTrace();
                        }
                        break;
                    } else {
                        try {
                            bzList.add(Float.valueOf(bz.substring(index2, index)));
                        } catch (NumberFormatException e) {
                            bzList.add(1f);
                            e.printStackTrace();
                        }
                    }
                    index2 = index + 1;
                }
                // 如果是封面页则不显示4和13的广告
                if (adPos == 2 && bzList != null) {
                    if (bzList.size() > 4) {
                        bzList.set(4, 0f);
                    }
                    if (bzList.size() > 13) {
                        bzList.set(13, 0f);
                    }
                }

                rate = new float[bzList.size()];
                float num = 0;
                for (float f : bzList) {
                    num += f;
                }
                for (int i = 0; i < bzList.size(); i++) {
                    rate[i] = bzList.get(i) / num * 10000;
                }
                int ran = new Random().nextInt(10000) + 1;
                num = 0;
                for (int i = 0; i < rate.length; i++) {
                    num += rate[i];
                    if (ran <= num) {
                        whichAd = i;
                        break;
                    }
                }
            }
            final float[] rate2 = rate;
            Runnable r = new Runnable() {
                @Override
                public void run() {
                    if (listener != null) {
                        listener.onIsShowAd(true);
                    }
                    showAD(testADID == -1 ? whichAd : testADID, rate2);
                }
            };
            context.runOnUiThread(r);
        } catch (Exception e) {
            if (listener != null) {
                listener.onIsShowAd(false);
            }
            e.printStackTrace();
        }
    }

    /**
     * 显示广告 7 11 15 29 30
     * 
     * @param which 显示哪个广告的序号
     * @param rate 显示广告的比重集合
     */
    private void showAD(final int which, final float[] rate) {
        try {
            Log.e(Tag, "----ad---" + which + ",rate=" + (rate == null ? "null" : rate.length));
            if (which < 0)
                return;
            whichAd = which;
            showedAd.add(whichAd);
            // final long startTime = System.currentTimeMillis();
            DisplayMetrics dm = new DisplayMetrics();
            context.getWindowManager().getDefaultDisplay().getMetrics(dm);
            if (adID == null || adID.length <= which || adID[which].length == 0) {
                showNextAd(which, rate);
                return;
            }
            // 如果当前广告此版本崩溃过，那就不在本版本显示了
            SharedPreferences sp = context.getSharedPreferences("sdk", Context.MODE_PRIVATE);
            if (sp.contains(Config.VERSION_INFO + "_" + which)) {
                // Log.e("--------------",com.sq.sdk.version.ConfigVersion.mVERSION_INFO
                // + "_" + which);
                showNextAd(which, rate);
                return;
            }
            sp =
                    context.getSharedPreferences(SHAREDPREFERENCE_FIRST_NAME + adPos,
                            Context.MODE_PRIVATE);
            boolean isSelfAd = false;
            Log.i(Tag, "which=" + which);
            if (which == 0) {
                content = sp.getString("content", "");
                link = sp.getString("link", "");
                show_type = sp.getString("show_type", "");
                isSelfAd = true;
                Log.i(Tag, "1.content=" + content + ",link=" + link);
            } else {
                String[] selfadids = sp.getString("selfadids", "").split(":");
                for (String id : selfadids) {
                    try {
                        if (!TextUtils.isEmpty(id)) {
                            int i = Integer.valueOf(id);
                            if (which + 1 == i) {
                                content = sp.getString("selfadid" + id + "content", "");
                                link = sp.getString("selfadid" + id + "link", "");
                                show_type = sp.getString("selfadid" + id + "show_type", "");
                                isSelfAd = true;
                                Log.i(Tag, "2.content=" + content + ",link=" + link);
                                break;
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            ViewGroup.LayoutParams rl;
            switch (which) {
                default:
                    if (isSelfAd) {
                        try {
                            new Thread() {
                                @Override
                                public void run() {
                                    if ("".equals(content)) {
                                        showNextAd(which, rate);
                                        return;
                                    }
                                    try {
                                        adBackground = getImgFromWeb(content);
                                        if (listener != null) {
                                            listener.onSuccess();
                                        }
                                        if (adBackground == null) {
                                            if (listener != null) {
                                                listener.onFail();
                                            }
                                            showNextAd(which, rate);
                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                    Runnable r = new Runnable() {
                                        @Override
                                        public void run() {
                                            showOldestAd();
                                        }
                                    };
                                    context.runOnUiThread(r);
                                }
                            }.start();
                        } catch (Exception e1) {
                            showNextAd(which, rate);
                            e1.printStackTrace();
                        }
                    } else {
                        showNextAd(which, rate);
                    }
                    break;
                case 1:// madhouse亿动智道130620版删除代码
                    break;
                case 2:// adchina(old)已下架
                    break;
                case 3:// iMocha 110526 已下架[20131023]
                    break;
                case 4:// adwo 110803
                       // com.adwo.adsdk.AdwoAdView adview = new com.adwo.adsdk.AdwoAdView(context,
                       // //
                       // Activity
                       // (String) adID[which][0], // Adwo_PID
                       // false,// 广告是否处于测试模式
                       // 0); // 广告请求时间间隔
                       // ((ViewGroup) context.findViewById(layoutID)).addView(adview, 0);
                       // if (hideID != 0) {
                       // context.findViewById(hideID).setVisibility(View.GONE);
                       // if (listener != null) {
                       // listener.onViewHided();
                       // }
                       // }
                       // final Map<String, Boolean> isShowNext = new HashMap<String, Boolean>();
                       // isShowNext.put("isshownext", true);
                       // adview.setListener(new com.adwo.adsdk.AdListener() {
                       // @Override
                       // public void onFailedToReceiveAd(final com.adwo.adsdk.AdwoAdView arg0,
                       // com.adwo.adsdk.ErrorCode arg1) {
                       // if (whichAd != 4) {
                       // return;
                       // }
                       // if (listener != null) {
                       // listener.onFail();
                       // }
                       //
                       // Log.e("-------adwo onFailedToReceiveAd-------", "arg1=" + arg1);
                       // if (isShowNext.get("isshownext")) {
                       // isShowNext.put("isshownext", false);
                       // showNextAd(which, rate);
                       // Runnable r = new Runnable() {
                       // @Override
                       // public void run() {
                       // arg0.setVisibility(View.GONE);
                       // }
                       // };
                       // context.runOnUiThread(r);
                       // }
                       // }
                       //
                       // @Override
                       // public void onReceiveAd(com.adwo.adsdk.AdwoAdView arg0) {
                       // if (whichAd != 4) {
                       // return;
                       // }
                       // if (listener != null) {
                       // listener.onSuccess();
                       // }
                       // if (hideID != 0) {
                       // Runnable r = new Runnable() {
                       // @Override
                       // public void run() {
                       // context.findViewById(hideID).setVisibility(View.GONE);
                       // }
                       // };
                       // context.runOnUiThread(r);
                       // if (listener != null) {
                       // listener.onViewHided();
                       // }
                       // }
                       // // Log.e("-------adwo onReceiveAd-------",arg0+"   &");
                       // Log.e(Tag, "-----adwo-----" + (System.currentTimeMillis() - startTime));
                       // }
                       // });
                    /*
                     * com.zkmm.adsdk.ZKMMAdView adview = new com.zkmm.adsdk.ZKMMAdView(context, //
                     * Activity (String) adID[which][0], // Adwo_PID false,// 广告是否处于测试模式 0); //
                     * 广告请求时间间隔 ((ViewGroup) context.findViewById(layoutID)).addView(adview, 0); if
                     * (hideID != 0) { context.findViewById(hideID).setVisibility(View.GONE); if
                     * (listener != null) { listener.onViewHided(); } } final Map<String, Boolean>
                     * isShowNext = new HashMap<String, Boolean>(); isShowNext.put("isshownext",
                     * true); adview.setListener(new com.zkmm.adsdk.AdListener() {
                     * 
                     * @Override public void onReceiveAd(ZKMMAdView arg0) {
                     * 
                     * if (whichAd != 4) { return; } if (listener != null) { listener.onSuccess(); }
                     * if (hideID != 0) { Runnable r = new Runnable() {
                     * 
                     * @Override public void run() {
                     * context.findViewById(hideID).setVisibility(View.GONE); } };
                     * context.runOnUiThread(r); if (listener != null) { listener.onViewHided(); } }
                     * // Log.e("-------adwo onReceiveAd-------",arg0+"   &");
                     * Log.e(Tag,"-----adwo-----"+(System.currentTimeMillis() - startTime));
                     * 
                     * }
                     * 
                     * @Override public void onFailedToReceiveAd(final ZKMMAdView arg0, ErrorCode
                     * arg1) { if (whichAd != 4) { return; } if (listener != null) {
                     * listener.onFail(); }
                     * Log.e("-------adwo onFailedToReceiveAd-------","arg1="+arg1); if
                     * (isShowNext.get("isshownext")) { isShowNext.put("isshownext", false);
                     * showNextAd(which, rate); Runnable r = new Runnable() {
                     * 
                     * @Override public void run() { arg0.setVisibility(View.GONE); } };
                     * context.runOnUiThread(r); }
                     * 
                     * } });
                     */
                    break;
                case 5:// vpon130620删除注释代码
                    break;
                case 6:// 友盟
                    break;
                case 7:// 百度
                    break;
                // case 8://帷千广告(已下架)
                // break;
                // case 9://LSense(已下架)
                // break;
                // case 10://youmi(已下架)
                // break;
                case 11:// domob
                    cn.domob.android.ads.DomobAdView domobAdview =
                            new cn.domob.android.ads.DomobAdView(context, (String) adID[which][0],
                                    (String) adID[which][1]);

                    rl =
                            new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                                    ViewGroup.LayoutParams.WRAP_CONTENT);
                    ((ViewGroup) context.findViewById(layoutID)).addView(domobAdview, 0, rl);
                    if (hideID != 0) {
                        context.findViewById(hideID).setVisibility(View.GONE);
                        if (listener != null) {
                            listener.onViewHided();
                        }
                    }
                    break;
                case 12:// adchina(new) 130620删除注释代码
                    break;
                case 13:// 替换新sdk 增加广告位
                    break;
                case 14:// suizong 下架
                    break;
                case 15:// mobisage
                    // if (android.os.Build.VERSION.SDK_INT < 8) {
                    // showNextAd(which, rate);
                    // break;
                    // }
                    // // com.mobisage.android.MobiSageAdBanner
                    // // mobisageBanner = new com.mobisage.android.MobiSageAdBanner(
                    // // context, (String) adID[which][0], null, null);
                    // MobiSageManager.getInstance().setPublisherID((String) adID[which][0]);
                    // mobisageBanner = new MobiSageAdBanner(context);
                    // mobisageBanner
                    // .setAdRefreshInterval(com.mobisage.android.MobiSageEnviroment.AdRefreshInterval.Ad_Refresh_15);
                    // mobisageBanner
                    // .setAnimeType(com.mobisage.android.MobiSageAnimeType.Anime_Random);
                    // ((ViewGroup) context.findViewById(layoutID)).addView(mobisageBanner, 0);
                    // // MobiSageAdBannerListener
                    // mobisageBanner
                    // .setMobiSageAdBannerListener(new
                    // com.mobisage.android.MobiSageAdBannerListener() {
                    //
                    // @Override
                    // public void onMobiSageBannerClick(MobiSageAdBanner arg0) {
                    //
                    // }
                    //
                    // @Override
                    // public void onMobiSageBannerClose(MobiSageAdBanner arg0) {
                    //
                    // }
                    //
                    // @Override
                    // public void onMobiSageBannerError(MobiSageAdBanner arg0) {
                    // if (whichAd != 15) {
                    // return;
                    // }
                    // if (listener != null) {
                    // listener.onFail();
                    // }
                    // Log.e(Tag, "---mobisage onFailedToReceiveAd---" + arg0);
                    // Runnable r = new Runnable() {
                    // @Override
                    // public void run() {
                    // mobisageBanner.destoryAdView();
                    // mobisageBanner = null;
                    // showNextAd(which, rate);
                    // }
                    // };
                    // context.runOnUiThread(r);
                    //
                    // }
                    //
                    // @Override
                    // public void onMobiSageBannerHide(MobiSageAdBanner arg0) {
                    //
                    // }
                    //
                    // @Override
                    // public void onMobiSageBannerHideWindow(MobiSageAdBanner arg0) {
                    //
                    // }
                    //
                    // @Override
                    // public void onMobiSageBannerPopupWindow(MobiSageAdBanner arg0) {
                    //
                    // }
                    //
                    // @Override
                    // public void onMobiSageBannerShow(MobiSageAdBanner arg0) {
                    // if (hideID != 0) {
                    // context.findViewById(hideID).setVisibility(View.GONE);
                    // if (listener != null) {
                    // listener.onViewHided();
                    // }
                    // }
                    // }
                    //
                    // });

                    // mobisageBanner.setMobiSageAdBannerListener(new
                    // com.mobisage.android.MobiSageAdBannerListener() {
                    // @Override
                    // public void onMobiSageAdViewClick(Object arg0) {
                    // }
                    //
                    // @Override
                    // public void onMobiSageAdViewClose(Object arg0) {
                    // }
                    //
                    // @Override
                    // public void onMobiSageAdViewError(Object arg0) {
                    // if (whichAd != 15) {
                    // return;
                    // }
                    // if (listener != null) {
                    // listener.onFail();
                    // }
                    // Log.e(Tag,"---mobisage onFailedToReceiveAd---"+ arg0);
                    // Runnable r = new Runnable() {
                    // @Override
                    // public void run() {
                    // mobisageBanner.destoryAdView();
                    // mobisageBanner = null;
                    // showNextAd(which, rate);
                    // }
                    // };
                    // context.runOnUiThread(r);
                    // }
                    //
                    // @Override
                    // public void onMobiSageAdViewHide(Object arg0) {
                    //
                    // }
                    //
                    // @Override
                    // public void onMobiSageAdViewShow(Object arg0) {
                    // if (hideID != 0) {
                    // context.findViewById(hideID).setVisibility(View.GONE);
                    // if (listener != null) {
                    // listener.onViewHided();
                    // }
                    // }
                    // }
                    //
                    //
                    // });
                    break;
                // case 16://dianru下架
                // break;
                // case 17://moku下架
                // break;
                // case 18://qumi下架
                // break;
                // case 27:
                // break;
                // case 28:// PunchBox 触控科技
                // break;
                // case 31: // 触控广告 下架
                // if (android.os.Build.VERSION.SDK_INT < 10) {
                // showNextAd(which, rate);
                // break;
                // }
                // String vName = "";
                // try {
                // PackageManager pm = context.getPackageManager();
                // PackageInfo pinfo = pm.getPackageInfo(context.getPackageName(),
                // PackageManager.GET_CONFIGURATIONS);
                // vName = pinfo.versionName;
                // } catch (Exception e) {
                // e.printStackTrace();
                // }
                // // 新增广告位
                // PunchBox.getInstance().init(context, (String) adID[which][0], "", vName); //
                // 传入广告id
                // eventAdView = new EventAdView(context);
                // rl = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                // ViewGroup.LayoutParams.WRAP_CONTENT);
                // ((ViewGroup) context.findViewById(layoutID)).addView(eventAdView, 0, rl);
                // // 构造一个请求对象,参数为广告尺寸类型,0 : 适合手机类型的广告尺寸; 1 :适合平板类型的广告尺寸;
                // EventAdRequest _request = new EventAdRequest(context, "punchbox");
                // // 设置广告监听,广告加载不同时段进行回调,如果不需要监听,可以不加此行代码
                // eventAdView.setAdListener(new AdListener() {
                // @Override
                // public void onReceiveAd() {
                // if (hideID != 0) {
                // context.findViewById(hideID).setVisibility(View.GONE);
                // if (listener != null) {
                // listener.onViewHided();
                // }
                // }
                // Log.e(Tag,"-------PunchBox onReceiveAd-------");
                // }
                //
                // @Override
                // public void onPresentScreen() {
                // }
                //
                // @Override
                // public void onFailedToReceiveAd(PBException arg0) {
                // if (whichAd != 28) {
                // return;
                // }
                // if (listener != null) {
                // listener.onFail();
                // }
                // Log.e(Tag,"-------PunchBox onFailedToReceiveAd-------"+ arg0.getErrorCode());
                // Runnable r = new Runnable() {
                // @Override
                // public void run() {
                // eventAdView.setVisibility(View.GONE);
                // showNextAd(which, rate);
                // }
                // };
                // context.runOnUiThread(r);
                // }
                //
                // @Override
                // public void onDismissScreen() {
                // }
                // });
                // eventAdView.setDisplayInterval(3 * 60); // 设置显示时长
                // // 正式加载广告
                // eventAdView.loadAd(_request);
                // break;
                case 29: // 宾谷(PingCoo)
                    // // String apikey = "1369021242404";
                    // PingCooApi.getInstacnce().initWithkey((String) adID[which][0], context);
                    // PingCooApi.getInstacnce().bannerShow(context,
                    // ((LinearLayout) context.findViewById(layoutID)));
                    break;
                case 32:// gdt ad com.qq.e.ads.AdView
                    com.qq.e.ads.AdView gdtadv =
                            new com.qq.e.ads.AdView(context, com.qq.e.ads.AdSize.BANNER,
                                    "100725237", (String) adID[which][0]);
                    rl =
                            new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                                    ViewGroup.LayoutParams.WRAP_CONTENT);
                    ((ViewGroup) context.findViewById(layoutID)).addView(gdtadv, rl);
                    com.qq.e.ads.AdRequest gdtadr = new com.qq.e.ads.AdRequest();
                    gdtadr.setTestAd(false);
                    gdtadv.fetchAd(gdtadr);
                    break;
                // case 33:// yunyunad 下架
                // break;
                case 35:
                    // InMobi.initialize(context, (String) adID[which][0]);
                    // // InMobi.setLogLevel(LOG_LEVEL.DEBUG);// 调试模式
                    // this.imBannerAdView =
                    // new IMBanner(context, (String) adID[which][0],
                    // this.getOptimalSlotSize(context));
                    // this.imBannerAdView.setIMBannerListener(new IMBannerListener() {
                    // @Override
                    // public void onShowBannerScreen(IMBanner arg0) {
                    // // Log.i(Tag, "---InMobi--- onShowBannerScreen()" + arg0);
                    // }
                    //
                    // @Override
                    // public void onLeaveApplication(IMBanner arg0) {
                    // Log.i(Tag, "---InMobi--- onLeaveApplication()" + arg0);
                    // }
                    //
                    // @Override
                    // public void onDismissBannerScreen(IMBanner arg0) {
                    // Log.i(Tag, "---InMobi--- onDismissBannerScreen()" + arg0);
                    // }
                    //
                    // @Override
                    // public void onBannerRequestSucceeded(IMBanner arg0) {
                    // Log.i(Tag, "key:" + (String) adID[which][0]);
                    // Log.i(Tag, "---InMobi--- onBannerRequestSucceeded()" + arg0);
                    // }
                    //
                    // @Override
                    // public void onBannerRequestFailed(IMBanner arg0, IMErrorCode arg1) {
                    // Log.i(Tag, "key:" + (String) adID[which][0]);
                    // Log.i(Tag, "---InMobi--- onBannerRequestFailed()" + arg0 + ",arg1:"
                    // + arg1 + "；slot:" + getOptimalSlotSize(context));
                    // if (whichAd != 35) {
                    // return;
                    // }
                    // if (listener != null) {
                    // listener.onFail();
                    // }
                    // Runnable r = new Runnable() {
                    // @Override
                    // public void run() {
                    // showNextAd(which, rate);
                    // }
                    // };
                    // context.runOnUiThread(r);
                    // }
                    //
                    // @Override
                    // public void onBannerInteraction(IMBanner arg0, Map<String, String> arg1) {
                    // Log.i(Tag, "---mogo--- onBannerInteraction()" + arg0);
                    // }
                    // });
                    // rl =
                    // new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                    // ViewGroup.LayoutParams.WRAP_CONTENT);
                    // ((ViewGroup) context.findViewById(layoutID)).addView(imBannerAdView, rl);
                    // imBannerAdView.loadBanner();
                    break;
                case 36:
                    // TODO 添加宜搜联盟广告
                    // AdTargeting.setTestMode(true);// 调试阶段请设置为true。
                    // this.adSwitchLayout =
                    // new AdSwitchLayout(context, AdSwitchLayout.AdType.BANNER,
                    // (String) adID[which][0]);
                    // // 注册广告事件监听器
                    // this.adSwitchLayout.setAdSwitchListener(new AdSwitchListener() {
                    //
                    // @Override
                    // public void onReceiveAd() {
                    // Log.i(Tag, "yisou onReceiveAd");
                    // }
                    //
                    // @Override
                    // public void onFailedToReceiveAd() {
                    // Log.i(Tag, "yisou onFailedToReceiveAd");
                    // if (whichAd != 36) {
                    // return;
                    // }
                    // if (listener != null) {
                    // listener.onFail();
                    // }
                    // Runnable r = new Runnable() {
                    // @Override
                    // public void run() {
                    // showNextAd(which, rate);
                    // }
                    // };
                    // context.runOnUiThread(r);
                    // }
                    //
                    // @Override
                    // public void onClick() {
                    // Log.i(Tag, "yisou onClick");
                    // }
                    // });
                    // rl =
                    // new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                    // ViewGroup.LayoutParams.WRAP_CONTENT);
                    // ((ViewGroup) context.findViewById(layoutID)).addView(adSwitchLayout, rl);
                    break;
                case 37:// 360广告
                {
                    DiandeBanner banner = new DiandeBanner(context, (String) adID[which][0]);
                    banner.setRequestCallBack(new DiandeResultCallback() {
                        @Override
                        public void onSuccess(boolean arg0, String arg1) {
                            Log.i(Tag, "360 onSuccess:" + arg0 + "," + arg1);
                        }

                        @Override
                        public void onFailed(String arg0) {
                            Log.i(Tag, "360 onFailed:" + arg0);
                            if (whichAd != 37) {
                                return;
                            }
                            if (listener != null) {
                                listener.onFail();
                            }
                            Runnable r = new Runnable() {
                                @Override
                                public void run() {
                                    showNextAd(which, rate);
                                }
                            };
                            context.runOnUiThread(r);
                        }

                        @Override
                        public void onAdShowSuccess(int arg0, String arg1) {
                            Log.i(Tag, "360 onAdShowSuccess:" + arg0 + "," + arg1);
                        }
                    });
                    rl =
                            new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                                    ViewGroup.LayoutParams.WRAP_CONTENT);
                    ((ViewGroup) context.findViewById(layoutID)).addView(banner, rl);
                    banner.show();
                }
                    break;
            }
        } catch (Exception e) {
            showNextAd(which, rate);
            e.printStackTrace();
        } catch (NoClassDefFoundError e) {
            showNextAd(which, rate);
            e.printStackTrace();
        }
    }

    /**
     * 显示下一个广告
     * 
     * @param which 显示哪个广告的序号
     * @param rate 显示广告的比重集合
     */
    private void showNextAd(final int which, final float[] rate) {
        Runnable r = new Runnable() {
            @Override
            public void run() {
                try {
                    if (hideID != 0) {
                        context.findViewById(hideID).setVisibility(View.GONE);
                        if (listener != null) {
                            listener.onViewHided();
                        }
                    }

                    float tempMax = 0;
                    int tempIndex = -1;
                    for (int i = 0; i < rate.length; i++) {
                        if (rate[i] > tempMax && rate[i] <= maxRate && i != maxIndex
                                && !showedAd.contains(i)) {
                            tempMax = rate[i];
                            tempIndex = i;
                        }
                    }
                    maxRate = tempMax;
                    maxIndex = tempIndex;
                    showAD(maxIndex, rate);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        context.runOnUiThread(r);
    }

    /**
     * 显示自主广告
     */
    private void showOldestAd() {
        try {
            if (!content.equals("")) {
                if (hideID != 0) {
                    context.findViewById(hideID).setVisibility(View.GONE);
                    if (listener != null) {
                        listener.onViewHided();
                    }
                }
                View foot = null;
                final DisplayMetrics dm = new DisplayMetrics();
                context.getWindowManager().getDefaultDisplay().getMetrics(dm);
                if (adBackground == null) {
                    return;
                }
                int h = adBackground.getHeight() * dm.widthPixels / adBackground.getWidth();// 110608
                // 控制不放大显示
                // if(h>adBackground.getHeight()){
                // h = adBackground.getHeight();
                // }
                foot = new ImageView(context);
                foot.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                        h));
                ImageView img = (ImageView) foot;
                img.setImageBitmap(adBackground);
                if ("1".equals(show_type)) {
                    sendAdCount(1);
                } else if ("2".equals(show_type)) {
                    sendAdCount(2);
                } else if ("3".equals(show_type)) {
                    sendAdCount(3);
                }
                foot.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        try {
                            if ("3".equals(show_type)) {// 弹出自己的网页
                                String url = null;
                                String serverList = WebDomains.getInstence().getShuqiWebDomains(context);;
                                if (TextUtils.isEmpty(serverList)) {
                                    url = link;
                                } else {
                                    String[] ss = serverList.split(",");
                                    boolean isOur = false;
                                    for (String s : ss) {
                                        if (!TextUtils.isEmpty(s) && link.contains(s)) {
                                            isOur = true;
                                            break;
                                        }
                                    }
                                    if (isOur) {
                                        url =
                                                link
                                                        + ((link.endsWith(".php")
                                                                || link.endsWith(".com") || link
                                                                    .endsWith("/")) ? "?" : "&")
                                                        + config_version;
                                    } else {
                                        url = link;
                                    }
                                }
                                Intent intent = new Intent(context, AdActivity.class);
                                intent.putExtra("url", url);
                                context.startActivity(intent);
                                sendAdCount(4);
                            } else if ("2".equals(show_type)) {// 确认下载
                                new Builder(context)
                                        .setTitle("是否下载该应用程序?")
                                        .setPositiveButton("确定",
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface arg0,
                                                            int arg1) {
                                                        String url = link;
                                                        // +
                                                        // ((link.endsWith(".php")||link.endsWith(".com"))?"?":"&")
                                                        // + config_version;
                                                        if (!url.startsWith("http://")) {
                                                            url =
                                                                    "http://m.shuqi.com/?"
                                                                            + config_version;
                                                        }
                                                        Uri uri = Uri.parse(url);
                                                        Intent web =
                                                                new Intent(Intent.ACTION_VIEW, uri);
                                                        context.startActivity(web);
                                                        sendAdCount(6);
                                                    }
                                                }).setNegativeButton("取消", null).show();
                                sendAdCount(5);
                            } else if ("1".equals(show_type)) {// 直接下载
                                String url = link;
                                // +
                                // ((link.endsWith(".php")||link.endsWith(".com"))?"?":"&")
                                // + config_version;
                                if (!url.startsWith("http://")) {
                                    url = "http://m.shuqi.com/?" + config_version;
                                }
                                Uri uri = Uri.parse(url);
                                Intent web = new Intent(Intent.ACTION_VIEW, uri);
                                context.startActivity(web);
                                sendAdCount(7);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
                ((ViewGroup) context.findViewById(layoutID)).addView(foot, 0);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /** 发送自主广告的统计 */
    // 366,367,368 215;369,370 216;371,372 217
    private void sendAdCount(final int type) {
        new Thread() {
            @Override
            public void run() {
                try {
                    String sendUrl =
                            UrlManager.getUrls(context, UrlManager.COLUMN_DOMAIN_APPINFO)[0]
                                    + ("/android/adi.php?whichad=" + (whichAd + 1) + "&" + config_version);
                    switch (type) {
                        case 1:// 展示网站链接
                            sendUrl += "&show_wap_count=1";
                            // PVCount.setPV(context.getApplicationContext(), PVCount.PVID_366);
                            StatisticsUtils.onEvent(context, StatisticsEventID.AD_VIEW_BANNER_SHOW);
                            break;
                        case 2:// 展示确认下载
                            sendUrl += "&show_ok_download_count=1";
                            // PVCount.setPV(context.getApplicationContext(), PVCount.PVID_367);
                            StatisticsUtils.onEvent(context, StatisticsEventID.AD_VIEW_BANNER_SHOW);
                            break;
                        case 3:// 展示直接下载
                            sendUrl += "&show_direct_download_count=1";
                            // PVCount.setPV(context.getApplicationContext(), PVCount.PVID_368);
                            StatisticsUtils.onEvent(context, StatisticsEventID.AD_VIEW_BANNER_SHOW);
                            break;
                        case 4:// 点击网页链接
                            sendUrl += "&click_wap_count=1";
                            // PVCount.setPV(context.getApplicationContext(), PVCount.PVID_369);
                            StatisticsUtils
                                    .onEvent(context, StatisticsEventID.AD_VIEW_BANNER_CLICK);
                            break;
                        case 5:// 点击确认下载链接
                            sendUrl += "&click_ok_download_count=1";
                            // PVCount.setPV(context.getApplicationContext(), PVCount.PVID_370);
                            StatisticsUtils
                                    .onEvent(context, StatisticsEventID.AD_VIEW_BANNER_CLICK);
                            break;
                        case 6:// 下载确认下载链接
                            sendUrl += "&ok_dowload_count=1";
                            // PVCount.setPV(context.getApplicationContext(), PVCount.PVID_371);
                            StatisticsUtils.onEvent(context, StatisticsEventID.AD_VIEW_BNNNER_DOWN);
                            break;
                        case 7:// 下载直接下载链接
                            sendUrl += "&direct_dowload_count=1";
                            // PVCount.setPV(context.getApplicationContext(), PVCount.PVID_372);
                            StatisticsUtils.onEvent(context, StatisticsEventID.AD_VIEW_BNNNER_DOWN);
                            break;
                    }
                    URL u = new URL(sendUrl);
                    Log.e(Tag, "selfad:" + sendUrl);
                    URLConnection conn = u.openConnection();
                    conn.getInputStream();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }

    /**
     * 从网络下载图片
     * 
     * @param url 网络图片地址
     */
    private Bitmap getImgFromWeb(String url) {
        Bitmap bitmap = null;
        try {
            url += "?" + config_version;
            for (int i = 0; i < 5; i++) {
                try {
                    URL u = new URL(url);
                    HttpURLConnection conn = (HttpURLConnection) u.openConnection();
                    conn.setDoInput(true);
                    conn.connect();
                    InputStream in = conn.getInputStream();
                    android.util.Log.e("janus", " in available:" + in.available());
                    int length = (int) conn.getContentLength();
                    if (length != -1) {
                        byte[] imgData = new byte[length];
                        byte[] temp = new byte[512];
                        int readLen = 0;
                        int destPos = 0;
                        while ((readLen = in.read(temp)) > 0) {
                            System.arraycopy(temp, 0, imgData, destPos, readLen);
                            destPos += readLen;
                        }
                        try {
                            bitmap = BitmapFactory.decodeByteArray(imgData, 0, imgData.length);
                        } catch (OutOfMemoryError e) {
                            bitmap = Bitmap.createBitmap(1, 1, null);
                            e.printStackTrace();
                        }
                    }
                    in.close();
                } catch (Exception e) {
                    try {
                        bitmap = Bitmap.createBitmap(1, 1, null);
                    } catch (Exception e2) {
                    }
                    android.util.Log.e("janus", " download exception:" + e.getLocalizedMessage());
                }
                if (bitmap != null) {
                    break;
                }
            }
            if (bitmap != null) {
                android.util.Log
                        .e("janus", " download url:" + url + " img:" + bitmap.getRowBytes());
            } else {
                android.util.Log.e("janus", " download url:" + url);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bitmap;
    }

    /**
     * 广告解析app
     */
    private class AdvertisingApp extends ModelBase implements HttpRequestListener {

        // public List<AdvertisingInfo> getInfos(String[] params) {
        // String url = this.getUrls(params);
        // AdvertisingHandler handler = this.getHandler();
        // List<AdvertisingInfo> result = null;
        // fetchInfos(handler, url);
        // result = handler.getParsedData();
        // return result;
        // }

        private HttpRequest httpRequest;
        private Context mContext;

        public AdvertisingApp(Context context) {
            this.mContext = context;
        }

        // public void fetchInfos(DefaultHandler handler, String url) {
        // try {
        // Log.w(Tag, "联网解析广告信息");
        // // XMLHelper.doParse(context, handler, url);
        // } catch (Exception e) {
        // Log.w(Tag, "handle:" + e.getMessage());
        // }
        // }

        // public AdvertisingHandler getHandler() {
        // return new AdvertisingHandler();
        // }

        // public String getUrls(String[] params) {
        // return url;
        // }

        class AdvertisingHandler extends HandlerBase {
            private List<AdvertisingInfo> list;
            private AdvertisingInfo info;

            public void startDocument() throws SAXException {
                list = new ArrayList<AdvertisingInfo>();
            }

            public void startElement(String namespaceURI, String localName, String qName,
                    Attributes attrs) throws SAXException {
                if ("ad".equals(localName)) {
                    info = new AdvertisingInfo();
                    info.setStatus(attrs.getValue("status"));
                    info.setContent(attrs.getValue("content"));
                    info.setLink(attrs.getValue("link"));
                    info.setRatio(attrs.getValue("ratio"));
                    info.setShow_type(attrs.getValue("show_type"));
                    info.setSelfadids(attrs.getValue("selfadid"));
                    list.add(info);
                    Log4an.e(Tag, "ratio=" + info.getRatio());
                    Log4an.i(Tag, "getContent=" + info.getContent());
                    Log4an.i(Tag, "getSelfadids=" + info.getSelfadids());
                } else if ("selfad".equals(localName)) {
                    info = new AdvertisingInfo();
                    info.setContent(attrs.getValue("content"));
                    info.setLink(attrs.getValue("link"));
                    info.setShow_type(attrs.getValue("show_type"));
                    list.add(info);
                    Log4an.i(Tag, "自主getContent=" + info.getContent());
                }
            }

            public List<AdvertisingInfo> getParsedData() {
                return list;
            }
        }

        @Override
        public void action(int actionCode, Object object) {
            fireEvent(actionCode, object);
        }

        @Override
        public List<BasicNameValuePair> setParams() {
            return null;
        }

        @Override
        public String getRequestUrl() {
            return url;
        }

        @Override
        public void loadData(Object... objs) {
            httpRequest =
                    new HttpRequest(context, getRequestUrl(), false,
                            this);
            httpRequest.setDataParseAdapter(new AdvertisingHandler());
            MyTask.runInBackground(httpRequest, true);
        }

        @Override
        public void onDestroy() {
            if (httpRequest != null) {
                httpRequest.abort();
            }
        }
    }

    /** 广告解析info */
    private class AdvertisingInfo {
        private String status;
        private String content;
        private String link;
        private String ratio;
        private String show_type;
        private String selfadids;

        public String getSelfadids() {
            return selfadids;
        }

        public void setSelfadids(String selfadids) {
            this.selfadids = selfadids;
        }

        public String getShow_type() {
            return show_type;
        }

        public void setShow_type(String show_type) {
            this.show_type = show_type;
        }

        public String getRatio() {
            return ratio;
        }

        public void setRatio(String ratio) {
            this.ratio = ratio;
        }

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

        public String getLink() {
            return link;
        }

        public void setLink(String link) {
            this.link = link;
        }
    }

    /**
     * 设置广告时间监听
     * 
     * @param listener 广告时间监听对象
     */
    public void setListener(Listener listener) {
        this.listener = listener;
    }

    /** 广告时间监听类 */
    public interface Listener {
        public void onSuccess();

        public void onFail();

        public void onViewHided();

        public void onIsShowAd(boolean isShowAd);
    }

    /** 当Activity onPause时执行 */
    public void onPause() {


    }

    /** 当Activity onResume时执行 */
    public void onResume() {
        try {
            // if (adChinaView != null) {
            // Log.e("---sq_ad---", "onResume");
            // com.adchina.android.ads.AdEngine.getAdEngine().addBannerAdView(adChinaView);
            // }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /** 当Activity onDestroy时执行 */
    public void onDestroy() {
        Log.i(Tag, "-- onDestroy()----------");
        // try {
        // if (mobisageBanner != null) {
        // mobisageBanner.destoryAdView();
        // }
        // } catch (Exception e) {
        // e.printStackTrace();
        // } catch (NoClassDefFoundError e) {
        // e.printStackTrace();
        // }

        // 谷歌广告
        // try {
        // if (this.imBannerAdView != null) {
        // this.imBannerAdView.destroy();
        // }
        // } catch (Exception e) {
        // e.printStackTrace();
        // } catch (NoClassDefFoundError e) {
        // e.printStackTrace();
        // }
    }

    /**
     * 谷歌获取屏幕尺寸
     */
    // private Integer getOptimalSlotSize(Activity ctxt) {
    // Display display =
    // ((WindowManager) ctxt.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    // DisplayMetrics displayMetrics = new DisplayMetrics();
    // display.getMetrics(displayMetrics);
    // double density = displayMetrics.density;
    // double width = displayMetrics.widthPixels;
    // int[][] maparray =
    // { {IMBanner.INMOBI_AD_UNIT_728X90, 728, 90},
    // {IMBanner.INMOBI_AD_UNIT_468X60, 468, 60},
    // {IMBanner.INMOBI_AD_UNIT_320X50, 320, 50}};
    //
    // for (int i = 0; i < maparray.length; i++) {
    // if (maparray[i][1] * density <= width) {
    // return maparray[i][0];
    // }
    // }
    // return IMBanner.INMOBI_AD_UNIT_320X50;
    // }

    @SuppressWarnings("unchecked")
    @Override
    public void onEvent(int event, Object data) {
        switch (event) {
            case EventTypeConstants.EVENT_SUCCESS:// 读取数据 写处理逻辑
                list = (List<AdvertisingInfo>) data;
                if (list != null && list.size() > 0) {
                    addData();
                }
                break;
            default:
                break;
        }
    }

}
